using System;
using System.Collections.Generic;
using PluginFrame;

namespace PcrDataStructure
{
	[Serializable]
	public class PcrInstrument : IPcrInstrument
	{
		private DateTime mDate;

		private string mID;

		private InstrumentType mType;

		private bool mIsOfflineData;

		private readonly string[] mChannelNames;

		private Dictionary<string, IChannelConfiguration> mChannelConfigurations;

		private readonly IPcrStructure mPcrStructure;

		private readonly double[] mChannelGain;

		private List<double>[] mChannelCellGain;

		public List<double>[] ChannelCellGain
		{
			get
			{
				return mChannelCellGain;
			}
			set
			{
				mChannelCellGain = value;
			}
		}

		public IPcrStructure PcrStructure
		{
			get
			{
				return mPcrStructure;
			}
		}

		public DateTime Date
		{
			get
			{
				return mDate;
			}
		}

		public string ID
		{
			get
			{
				return mID;
			}
			set
			{
				mID = value;
			}
		}

		public InstrumentType Type
		{
			get
			{
				return mType;
			}
			set
			{
				mType = value;
			}
		}

		public bool IsOfflineData
		{
			get
			{
				return mIsOfflineData;
			}
			set
			{
				mIsOfflineData = value;
			}
		}

		public string[] ChannelNames
		{
			get
			{
				return mChannelNames;
			}
		}

		public Dictionary<string, IChannelConfiguration> ChannelConfigurations
		{
			get
			{
				return mChannelConfigurations;
			}
		}

		public PcrInstrument(IPcrStructure pcrStructure)
		{
			mIsOfflineData = true;
			mPcrStructure = pcrStructure;
			IChannelConfiguration[] channelConfigurations = mPcrStructure.ChannelConfigurations;
			mChannelNames = new string[channelConfigurations.Length];
			mChannelGain = new double[channelConfigurations.Length];
			mChannelCellGain = new List<double>[channelConfigurations.Length];
			for (int i = 0; i < mChannelCellGain.Length; i++)
			{
				mChannelCellGain[i] = new List<double>();
			}
		}

		public double GetChannelGain(int channelIndex)
		{
			if (channelIndex >= 0 && channelIndex < mChannelGain.Length)
			{
				return mChannelGain[channelIndex];
			}
			return 1.0;
		}

		public void SetChannelGain(int channelIndex, double value)
		{
			if (channelIndex >= 0 && channelIndex < mChannelGain.Length)
			{
				mChannelGain[channelIndex] = value;
			}
		}

		public void InitializeInstrumentData(string instrumentID, byte[] channelData, bool isOfflineData)
		{
			mIsOfflineData = isOfflineData;
			mID = instrumentID;
			mChannelConfigurations = new Dictionary<string, IChannelConfiguration>();
			for (int i = 0; i < channelData.Length; i++)
			{
				if (channelData[i] > 0 && channelData[i] <= channelData.Length)
				{
					mPcrStructure.ChannelConfigurations[i].IsAvailable = true;
					mChannelNames[i] = mPcrStructure.ChannelConfigurations[i].Content;
					mChannelConfigurations.Add(mChannelNames[i], mPcrStructure.ChannelConfigurations[i]);
				}
				else
				{
					mPcrStructure.ChannelConfigurations[i].IsAvailable = false;
					mChannelNames[i] = string.Empty;
				}
			}
		}

		public string GenerateInstrumentID()
		{
			return string.Empty;
		}
	}
}
